#==============================================================================
# Theta Scripting Engine - Mirage by privateer
#==============================================================================
# ► Version  : 1.0
#==============================================================================
# ► Introduction
# This script will let you create a state that negate any additional states
# upon an action. So, as long as an unit has a Mirage state, actions done on
# him/her will only damage him/her.
#==============================================================================
# ► Instruction
# Just put this script anywhere below Scene_Debug but above Main.
#==============================================================================
# ► Compatibility
# Designed and tested for DBS. May or not work with exotic CBS and/or scripts
# that alter how a state is added.
#==============================================================================

module TSE
  module Mirage
    # Put any state id(s) that will be regarded as Mirage state.
    MIRAGE_STATES = [18]
    
    # Put any states that'll still be applied even if the target has Mirage.
    # By default, states with Regard as HP 0 will have this trait.
    MIRAGE_UNAFFECTED = []
    
    # Message that will be displayed when an unit with Mirage negated the states.
    MIRAGE_MESSAGE = "Negated!"
  end
end

#==============================================================================
# DON'T EDIT ANY FURTHER UNLESS YOU KNOW WHAT YOU'RE DOING!
#==============================================================================

$imported = {} if $imported.nil?
$imported["TSE-Mirage"] = true


class RPG::State
  include TSE
  include Mirage
  def mirage?
    return MIRAGE_STATES.include?(id)
  end
  def mirage_unaffected?
    return MIRAGE_UNAFFECTED.include?(id)
  end
end

class Game_Battler
  include TSE
  include Mirage
  def has_mirage?
    return @states.any?{|state|$data_states[state].mirage?}
  end
  
  alias tse_mirage_add_state add_state
  def add_state(state_id, force = false)
    return tse_mirage_add_state(state_id, force = false) if $data_states[state_id].zero_hp
    unless self.has_mirage?
      tse_mirage_add_state(state_id, force = false)
    else
      if $data_states[state_id].mirage_unaffected?
        tse_mirage_add_state(state_id, force = false)
      else
        self.damage = MIRAGE_MESSAGE
      end
    end
  end
end
